from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv

from .const import DOMAIN, PLATFORMS, DOMAIN_WEB, VERSION

CONFIG_SCHEMA = cv.deprecated(DOMAIN)

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    # hass.config_entries.async_setup_platforms(entry, PLATFORMS)
    
    hass.http.register_static_path(DOMAIN_WEB, hass.config.path("custom_components/" + DOMAIN + "/www"), False)
    hass.components.frontend.async_register_built_in_panel(
                        "iframe",
                        "浏览器主页",
                        "mdi:microsoft-internet-explorer",
                        DOMAIN,
                        { "url": f"{DOMAIN_WEB}/index.html?ver={VERSION}" },
                        require_admin=entry.options.get('require_admin', False))
    entry.async_on_unload(entry.add_update_listener(update_listener))
    return True

async def update_listener(hass, entry):
    """Handle options update."""
    await async_unload_entry(hass, entry)
    await async_setup_entry(hass, entry)

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    hass.components.frontend.async_remove_panel(DOMAIN)
    # return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
    return True